package com.doushu.dispatch.controller;

import com.doushu.dispatch.common.dto.ResultDto;
import com.doushu.dispatch.service.UtilsService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Api(description = "工具controller")
public class UtilsController {

    @Autowired
    private UtilsService utilsService;

    @RequestMapping(value = "/dataVer", method = RequestMethod.POST)
    @ApiOperation(value = "数据同步", httpMethod = "POST")
    public ResultDto dataVer(
            @ApiParam(name = "shopId",value="店铺id",required = true,example = "0")@RequestParam Long shopId) {
        return utilsService.dataVer(shopId);
    }

    @RequestMapping(value = "/itemGetInfo", method = RequestMethod.POST)
    @ApiOperation(value = "推送单个单品给插件", httpMethod = "POST")
    public ResultDto itemGetInfo(
            @ApiParam(name = "itemId",value="商品id",example = "0")@RequestParam(required = false) Long itemId,
            @ApiParam(name = "type",value="消息类型",defaultValue = "getItem")@RequestParam(required = false,defaultValue = "getItem") String type,
            @ApiParam(name = "shopId",value="店铺id",required = true,example = "0")@RequestParam Long shopId,
            @ApiParam(name = "start_date",value="数据开始日期,yyy-MM-dd",required = true)@RequestParam String start_date,
            @ApiParam(name = "end_date",value="数据结束日期,yyy-MM-dd",required = true)@RequestParam String end_date,
            @ApiParam(name = "token",value="登录的token",required = true,defaultValue = "0")@RequestParam(defaultValue = "0") String token,
            @ApiParam(name = "force",value="强制推送",required = true,defaultValue = "0",example = "0")@RequestParam(defaultValue = "0") Integer force) {
        return utilsService.itemGetInfo(itemId,type,shopId,start_date,end_date,token,force);
    }

    @RequestMapping(value = "/push", method = RequestMethod.POST)
    @ApiOperation(value = "推送消息给插件", httpMethod = "POST")
    public ResultDto push(
            @ApiParam(name = "type",value="消息类型",defaultValue = "getPlan")@RequestParam(required = false,defaultValue = "getPlan") String type,
            @ApiParam(name = "shopId",value="店铺id",required = true ,example = "0")@RequestParam Long shopId,
            @ApiParam(name = "token", value = "登录的token")@RequestParam(required = false) String token,
            @ApiParam(name = "campaignId", value = "推广计划id",example = "0")@RequestParam(required = false) Integer campaignId,
            @ApiParam(name = "adGroupId", value = "指定商品id",example = "0")@RequestParam(required = false) Long adGroupId,
            @ApiParam(name = "firstCat", value = "根分类id",example = "0")@RequestParam(required = false) Integer firstCat,
            @ApiParam(name = "trafficType", value = "来源+终端类型")@RequestParam(required = false) String trafficType,
            @ApiParam(name = "crowdIds", value = "人群id")@RequestParam(required = false) String crowdIds,
            @ApiParam(name = "discount", value = "溢价,例：溢价5%.则填写105,以此类推.最高溢价300%",example = "0")@RequestParam(required = false) Integer discount,
            @ApiParam(name = "productId", value = "未知",example = "101001005",defaultValue = "101001005")@RequestParam(required = false,defaultValue = "101001005") Integer productId,
            @ApiParam(name = "name", value = "人群名称")@RequestParam(required = false) String name,
            @ApiParam(name = "onlineStatus", value = "推广状态;0暂停1参与",example = "0")@RequestParam(required = false) Integer onlineStatus,
            @ApiParam(name = "startDate", value = "开始日期,yyy-MM-dd")@RequestParam(required = false) String startDate,
            @ApiParam(name = "endDate", value = "结束日期,yyy-MM-dd")@RequestParam(required = false) String endDate){
        return utilsService.push(type,shopId,token,campaignId,adGroupId,firstCat,trafficType,crowdIds,discount,productId,name,onlineStatus,startDate,endDate);
    }

    @RequestMapping(value = "/receiveMsg", method = RequestMethod.POST)
    @ApiOperation(value = "接收消息", httpMethod = "POST")
    public ResultDto receiveMsg(
            @ApiParam(name = "msg", value = "消息数据", required =true)@RequestParam String msg){
        return utilsService.receiveMsg(msg);
    }

    @RequestMapping(value = "/pushNotice", method = RequestMethod.POST)
    @ApiOperation(value = "给在线用户推送广告", httpMethod = "POST")
    public ResultDto pushNotice(
            @ApiParam(name = "head", value = "标题", required =true)@RequestParam String head,
            @ApiParam(name = "content", value = "内容", required =true)@RequestParam String content){
        return utilsService.pushNotice(head,content);
    }

    @RequestMapping(value = "/refreshChrome", method = RequestMethod.POST)
    @ApiOperation(value = "刷新所有在线用户的插件", httpMethod = "POST")
    public ResultDto refreshChrome(){
        return utilsService.refreshChrome();
    }
}
